package com.cat.dataStructure03;

import java.util.HashSet;

/**
 * @author 曲大人的喵
 * @description https://leetcode.cn/contest/weekly-contest-476/problems/count-distinct-integers-after-removing-zeros/
 * @create 2025/11/16 10:34
 * @since JDK17
 */

class Solution68 {
    public long countDistinct(long n) {
        char[] s = Long.toString(n).toCharArray();
        int m = s.length;
        long pow9 = (long) Math.pow(9, m);
        long ans = (pow9 - 9) / 8;
        for (int i = 0; i < m; i++) {
            if (s[i] == '0') {
                break;
            }
            long y = s[i] - '1';
            if (i == m - 1) {
                y++;
            }
            pow9 /= 9;
            ans += y * pow9;
        }

        return ans;
    }
}
